package me.zk.practice1.s;

/**
 * @author zhangkai
 * @date 2023/7/30 15:15
 */
public class LS121 {
    public int maxProfit(int[] prices) {
        int max = 0;
        for (int i = 0; i < prices.length; i++) {
            for (int j = i+1; j < prices.length; j++) {
                max = Math.max(prices[j]-prices[i],max);
            }
        }
        return max;
    }

    public int maxProfit2(int[] prices) {
        int max = 0;
        int min = Integer.MAX_VALUE;
        for (int price : prices) {
            min = Math.min(price, min);

            max = Math.max(max, price - min);
        }
        return max;
    }
}
